package com.jerry.base.java8.closure;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * 闭包的使用
 *
 * @author Jerry
 * @since 2024/7/31 21:31
 */
public class ClosureUsage {

    public static void main(String[] args) throws IOException {
        // 创建10个任务对象，并给每一个任务一个编号
        List<Runnable> runnableList = new ArrayList<>();

        for (int i = 0; i < 10; i++) {
            final int id = i + 1;
            Runnable task = () -> System.out.println(Thread.currentThread() + "执行任务" + id);
            runnableList.add(task);
        }

        ExecutorService service = Executors.newWorkStealingPool();

        for (Runnable task : runnableList) {
            service.submit(task);
        }
        System.in.read();
    }
}
